import { connect } from 'react-redux'
import React from 'react'
import {addTodo} from '../actions'

const AddTodo = ({dispatch}) => {
    let input
    return(
        <div>
            <form onSubmit={e => {
                e.preventDefault()
                if(!input.value.trim()){
                    return
                } dispatch(addTodo(input.value))
                input.value = ''
            }}>
                <input className="addTodo" ref={node => (input = node)} />
                <button type="submit">+ Todo hinzufügen</button>
            </form>
        </div>
    )
}

export default connect()(AddTodo)